-
Notifications
You must be signed in to change notification settings - Fork 469
fix(fastapi): apply tracing to user middlewares in fastapi #4478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mabdinur
commented
Nov 4, 2022
a07a1f8 to
95ff33e
Compare
95ff33e to
b9f8cad
Compare
releasenotes/notes/fastapi-fix-middlewares-705975a535daaea8.yaml
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## 1.x #4478 +/- ##
==========================================
- Coverage 74.62% 74.61% -0.01%
==========================================
Files 811 811
Lines 62335 62357 +22
==========================================
+ Hits 46515 46527 +12
- Misses 15820 15830 +10
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
ZStriker19
reviewed
Dec 22, 2022
releasenotes/notes/fastapi-fix-middlewares-705975a535daaea8.yaml
Outdated
Show resolved
Hide resolved
mabdinur
commented
Dec 22, 2022
releasenotes/notes/fastapi-fix-middlewares-705975a535daaea8.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Brett Langdon <[email protected]>
f8f8da6 to
68cd3fa
Compare
ZStriker19
previously approved these changes
Dec 22, 2022
Yun-Kim
reviewed
Dec 23, 2022
releasenotes/notes/fastapi-fix-middlewares-705975a535daaea8.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Yun Kim <[email protected]>
emmettbutler
requested changes
Jan 27, 2023
emmettbutler
previously approved these changes
Feb 2, 2023
ZStriker19
previously approved these changes
Feb 6, 2023
ZStriker19
approved these changes
Feb 7, 2023
emmettbutler
approved these changes
Feb 8, 2023
8 tasks
majorgreys
pushed a commit
that referenced
this pull request
Feb 10, 2023
## Description Resolve: #4397 In Starlette and FastAPI applications the last middleware configured is the first one called ([here](https://github.com/encode/starlette/blob/0.21.0/starlette/applications.py#L168)). The fastapi trace middleware is applied when a fastapi application is created ([fastapi.FastAPI()](https://github.com/DataDog/dd-trace-py/blob/a21c8dbc433577245f5c145fd46f2a3dc4540402/ddtrace/contrib/fastapi/patch.py#L38)). If another middleware is configured after an application is initialized it will not be traced. Here's an example of a fastapi middleware being configured after `fastapi.FastApi()` is called: https://fastapi.tiangolo.com/tutorial/middleware/#create-a-middleware. Note - This PR only ensures Fastapi middlewares are traced. Supporting all starlette middlewares is out of scope. ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. Co-authored-by: Brett Langdon <[email protected]> (cherry picked from commit b5a4511)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Resolve: #4397
In Starlette and FastAPI applications the last middleware configured is the first one called (here). The fastapi trace middleware is applied when a fastapi application is created (fastapi.FastAPI()). If another middleware is configured after an application is initialized it will not be traced.
Here's an example of a fastapi middleware being configured after
fastapi.FastApi()is called: https://fastapi.tiangolo.com/tutorial/middleware/#create-a-middleware.Note - This PR only ensures Fastapi middlewares are traced. Supporting all starlette middlewares is out of scope.
Reviewer Checklist
changelog/no-changeloglabel added.